package fr.ralmn.OgameDroid.Frame;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import fr.ralmn.OgameDroid.R;
import fr.ralmn.OgameDroid.Util;
import fr.ralmn.OgameDroid.Object.Batiment;
import fr.ralmn.OgameDroid.Object.Objects;
import fr.ralmn.OgameDroid.Object.Technologie;

public class Ressource_ressources extends Fragment {

	public static Batiment technologie = Objects.metal;
	private int LEVEL = 1;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		final View v = inflater.inflate(R.layout.techno_ressource, container,
				false);
		technologie = Util.getBatiment(getActivity().getIntent().getExtras()
				.getString("technologie"));
		final EditText lvl_txt = (EditText) v.findViewById(R.id.lvl_techno_r);

		lvl_txt.addTextChangedListener(new TextWatcher() {

			@Override
			public void onTextChanged(CharSequence s, int start, int before,
					int count) {
			}

			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {
			}

			@Override
			public void afterTextChanged(Editable s) {
				LEVEL = Integer.parseInt(lvl_txt.getText().toString());
				calc(v);
			}
		});

		Button lvl_btn = (Button) v.findViewById(R.id.btn_lvl_techno_r);
		calc(v);
		lvl_btn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				LEVEL = Integer.parseInt(lvl_txt.getText().toString());
				calc(v);
			}
		});

		return v;
	}

	public final void calc(View v) {

		TextView o2_metal = (TextView) v.findViewById(R.id.metal_coast_techno);
		o2_metal.setText(technologie.getCoastMetal(LEVEL) + "");

		TextView o2_cristal = (TextView) v
				.findViewById(R.id.cristal_coast_techno);
		o2_cristal.setText(technologie.getCoastCristal(LEVEL) + "");

		TextView o2_deuterium = (TextView) v
				.findViewById(R.id.deute_coast_techno);
		o2_deuterium.setText(technologie.getCoastDeterium(LEVEL) + "");

	}

}
